<?php

/**
 * Singleton class for page content
 *
 * @author Honza
 */
class Page {

  
  private $head = '';    //head tag of html
  
  //content of body
  private $logo = '';
  private $nav = '';
  private $sidebar = '';
  private $content = '';
  private $footer = '';
  
  private static $instance; //instance

  private function __construct() {
    
  }

  /**
   * 
   * @return singleton instance of page object
   */
  public static function getInstance() {
    if (self::$instance == NULL) {
      self::$instance = new Page();
    }
    return self::$instance;
  }

  /**
   * Add string between <head> element
   */
  public function addToHead($text) {
    $this->head .= $text;
  }

  /**
   * Add string nav
   */
  public function addToNav($text) {
    $this->nav .= $text;
  }
  
  public function clearNav() {
    $this->nav = '';
  }

  /**
   * Add string logo
   */
  public function addToLogo($text) {
    $this->logo .= $text;
  }

  /**
   * Add string sidebar
   */
  public function addToSidebar($text) {
    $this->sidebar .= $text;
  }

  /**
   * Add string content
   */
  public function addToContent($text) {
    $this->content .= $text;
  }

  /**
   * Add string footer
   */
  public function addToFooter($text) {
    $this->footer .= $text;
  }

  public function __toString() {
    $page = '<!DOCTYPE HTML><html>';
    $page .= $this->head;

    $page .= '<body>';
    $page .= '<div id="main">';
    $page .= '<header>';
    $page .= $this->logo;
    $page .= '<nav>';
    $page .= $this->nav;
    $page .= '</nav>';
    $page .= '</header>';
    $page .= '<section id="site_content">';
    $page .= '<aside id="sidebar_container">';
    $page .= $this->sidebar;
    $page .= '</aside>';
    $page .= '<aside id="content">';
    $page .= $this->content;
    $page .= '</aside>';
    $page .= '</section>';
    $page .= '<footer>';
    $page .= $this->footer;
    $page .= '</footer>';
    $page .= '</div>';
    $page .= '</body>';
    $page .= '</html>';

    return $page;
  }
} // end of class
?>
